package com.zhangtai.modules.dao;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zhangtai.modules.dto.DimissionInfoDto;
import com.zhangtai.modules.entity.employee.DimissionInfoEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * 
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2020-08-31 11:54:05
 */
@Mapper
public interface DimissionInfoDao extends BaseMapper<DimissionInfoEntity> {


    @Select("SELECT count(id) FROM tb_dimission_info WHERE inset_date = #{insetDate}")
    Long getDimissionInfoNum(@Param("insetDate")String insetDate);


    @Select("<script> SELECT tdi.*, tei.NAME, tei.code, tei.job_id,tei.jobname,tei.unit_id,tei.unitname," +
            " tei.org_id,tei.orgname,tei.job_Level_id,tei.job_level,tei.job_level_type,tei.hiredate FROM tb_dimission_info tdi " +
            "   LEFT JOIN tb_employee_info tei ON tei.oid = tdi.oid " +
            "  <where> tdi.is_delete = 0" +
            "<if test='orgIds!=null and orgIds.size>0'> and tdi.unit_id in " +
            " <foreach item=\"orgId\" index=\"index\" collection=\"orgIds\" open=\"(\" separator=\",\" close=\")\">#{orgId}</foreach>" +
            "</if>"+
            "<if test='orgIds==null or orgIds.size==0'> and tdi.unit_id = null </if>" +
            "<if test='oid!=null'> and tei.oid = #{oid} </if>" +
            "<if test='name!=null'> and tei.name like '%${name}%' </if>" +
            "<if test='code!=null'> and tei.code like '%${code}%' </if>" +
            "<if test='hiredateStart!=null'> and tei.hiredate &gt;= #{hiredateStart} </if>" +
            "<if test='hiredateEnd!=null'> and tei.hiredate &lt;= #{hiredateEnd} </if>" +
            "<if test='rurnoverStatus!=null'> and tdi.rurnover_status = #{rurnoverStatus} </if>" +
            "<if test='rurnoverStatus==null'> and tdi.rurnover_status != '2' </if>" +
            "</where>  ORDER BY tdi.create_time DESC " +
           // "</where>  ORDER BY tdi.create_time DESC ,tdi.rurnover_status asc" +
            "</script>")
    List<DimissionInfoDto> getDimissionInfoPage( @Param("orgIds") List<Long> orgIds,
                                                   @Param("oid") String oid,
                                                  @Param("name") String name,
                                                  @Param("code") String code,
                                                  @Param("hiredateStart") String hiredateStart,
                                                  @Param("hiredateEnd") String hiredateEnd,
                                                   @Param("rurnoverStatus") Integer rurnoverStatus,
                                           Page<DimissionInfoDto> page);
    @Select("<script> SELECT tdi.*, tei.NAME, tei.code, tei.job_id,tei.jobname,tei.unit_id,tei.unitname," +
            " tei.org_id,tei.orgname,tei.job_Level_id,tei.job_level,tei.job_level_type,tei.hiredate FROM tb_dimission_info tdi " +
            "   LEFT JOIN tb_employee_info tei ON tei.oid = tdi.oid " +
            "  <where> tdi.is_delete = 0" +
            "<if test='orgIds!=null and orgIds.size>0'> and tdi.unit_id in " +
            " <foreach item=\"orgId\" index=\"index\" collection=\"orgIds\" open=\"(\" separator=\",\" close=\")\">#{orgId}</foreach>" +
            "</if>"+
            "<if test='orgIds==null or orgIds.size==0'> and tdi.unit_id = null </if>" +
            "<if test='oid!=null'> and tei.oid = #{oid} </if>" +
          //  "<if test='name!=null'> and tei.name like '%${name}%' </if>" +
           // "<if test='code!=null'> and tei.code like '%${code}%' </if>" +
           // "<if test='hiredateStart!=null'> and tei.hiredate &gt;= #{hiredateStart} </if>" +
           // "<if test='hiredateEnd!=null'> and tei.hiredate &lt;= #{hiredateEnd} </if>" +
           // "<if test='rurnoverStatus!=null'> and tdi.rurnover_status = #{rurnoverStatus} </if>" +
           // "<if test='rurnoverStatus==null'> and tdi.rurnover_status != '2' </if>" +
            "</where>  ORDER BY tdi.create_time DESC " +
            // "</where>  ORDER BY tdi.create_time DESC ,tdi.rurnover_status asc" +
            "</script>")
    List<Map<String,Object>> getDimissionInfoPageTwo( @Param("orgIds") List<Long> orgIds,
                                                   @Param("oid") String oid,
                                                 //  @Param("name") String name,
                                                //   @Param("code") String code,
                                                 //  @Param("hiredateStart") String hiredateStart,
                                                 //  @Param("hiredateEnd") String hiredateEnd,
                                                 //  @Param("rurnoverStatus") Integer rurnoverStatus,
                                                   Page<DimissionInfoDto> page);
}
